package com.awspaas.user.apps.shhtaerospaceindustrial.healthmeaasge;

import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.shhtaerospaceindustrial.util.CoreUtil;

import java.util.List;
import java.util.Map;

@Controller
public class AppointmentReviewProjectQueryCmd {
	/**
	 * @Desc 根据检查项目信息查询项目类别信息
	 * @param uc
	 * @param
	 * @return检查项目表(BO_EU_CHECKITEM)
	 */
	@Mapping("com.awspaas.user.apps.AppointmentReviewProjectType")
	public static String getDrugAddress(UserContext uc) {
		JSONObject result = new JSONObject();
		try {
			String queryUrl ="SELECT distinct(PROJECTTYPE) FROM BO_EU_CHECKITEM order by PROJECTTYPE desc" ;
			List<Map<String, Object>> urlList = DBSql.query(queryUrl, new ColumnMapRowMapper(), new Object[]{});
			if(urlList == null || urlList.isEmpty()) {
				result.put("status", "1");
				result.put("message", "未查询到检查项目类别信息。");
				return result.toString();
			}
			JSONArray tececaiArr = new JSONArray();
			for (int i = 0; i < urlList.size(); i++) {
				Map<String, Object> urlMap = urlList.get(i);
				JSONObject tececaitem = new JSONObject();
				String PROJECTTYPE = CoreUtil.objToStr(urlMap.get("PROJECTTYPE"));//项目类别
				tececaitem.put("projecttype", PROJECTTYPE);
				tececaiArr.add(tececaitem);
			}
				result.put("status", "0");
				result.put("tececaiArr", tececaiArr);

		} catch (Exception e) {
			e.printStackTrace();
			result.put("status", "1");
			result.put("message", e.getMessage());
		}
		return result.toString();
	}
	
	/**
	 * @Desc 根据项目类别，查询该项目类别下的项目信息
	 * @param uc
	 * @param wgdname  药品地址
	 * @return
	 */
	@Mapping("com.awspaas.user.apps.AppointmentReviewProject")
	public static String getDrugInformation(UserContext uc, String projecttype) {
		JSONObject result = new JSONObject();
		try {
			String queryUrl =
			    "SELECT BINDID,ID,ENTRYNAME,PRICE,PROJECTTYPE,SUITPEOPLE,USERSELECT,CHECKRANGE,DETECTION,TABOO,PROJECTNO " +
					" FROM BO_EU_CHECKITEM  WHERE PROJECTTYPE =  '"+projecttype+"'";
			List<Map<String, Object>> urlList = DBSql.query(queryUrl, new ColumnMapRowMapper(), new Object[]{});
			if(urlList == null || urlList.isEmpty()) {
				result.put("status", "1");
				result.put("message", "未查询到该检查项目类别下的检查项信息。");
				return result.toString();
			}
			JSONArray tececaiArr = new JSONArray();
			for (int i = 0; i < urlList.size(); i++) {
				Map<String, Object> urlMap = urlList.get(i);
				JSONObject tececaitem = new JSONObject();
				String bindid = CoreUtil.objToStr(urlMap.get("BINDID"));
				String boId = CoreUtil.objToStr(urlMap.get("ID"));
				String ENTRYNAME = CoreUtil.objToStr(urlMap.get("ENTRYNAME"));
				Double PRICE = CoreUtil.objToDouble(urlMap.get("PRICE"));
				String PROJECTTYPE = CoreUtil.objToStr(urlMap.get("PROJECTTYPE"));
				String SUITPEOPLE = CoreUtil.objToStr(urlMap.get("SUITPEOPLE"));
				String USERSELECT = CoreUtil.objToStr(urlMap.get("USERSELECT"));
				String CHECKRANGE = CoreUtil.objToStr(urlMap.get("CHECKRANGE"));
				String DETECTION = CoreUtil.objToStr(urlMap.get("DETECTION"));
				String TABOO = CoreUtil.objToStr(urlMap.get("TABOO"));
				String PROJECTNO = CoreUtil.objToStr(urlMap.get("PROJECTNO"));
				tececaitem.put("bindid", bindid);
				tececaitem.put("boId", boId);
				tececaitem.put("entryname", ENTRYNAME);//项目名称
				tececaitem.put("price", PRICE);//单价
				tececaitem.put("projecttype", PROJECTTYPE);//项目类别
				tececaitem.put("suitpeople", SUITPEOPLE);//适用人群
				tececaitem.put("userselect", USERSELECT);//用户自选
				tececaitem.put("checkrange", CHECKRANGE);//检查范围
				tececaitem.put("detection", DETECTION);//检测意义
				tececaitem.put("taboo", TABOO);//禁忌人群
				tececaitem.put("projectno", PROJECTNO);//项目编号
				tececaiArr.add(tececaitem);
			}
				result.put("status", "0");
				result.put("tececaiArr", tececaiArr);

		} catch (Exception e) {
			e.printStackTrace();
			result.put("status", "1");
			result.put("message", e.getMessage());
		}
		return result.toString();
	}
}
